package com.flute.haflute.net;

import gnu.cajo.invoke.Remote;

import java.io.IOException;
import java.net.MalformedURLException;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;

import com.flute.haflute.common.ClusterContext;

/**
 * 基于RMI和CAJO的远程服务查询和调用接口，封装的目的在于屏蔽具体是哪种框架提供远程服务。
 * 
 */
public class RMINetClient {
	private static String rmiURI = "//" + ClusterContext.getDM() + ":"
			+ (ClusterContext.getRMIPort() - 1) + "/";

	public static Object getServiceObject(String serviceName)
			throws RemoteException, MalformedURLException, NotBoundException,
			IOException, ClassNotFoundException, InstantiationException,
			IllegalAccessException {
		return Remote.getItem(rmiURI + serviceName);
	}

	public static Object invoke(Object serviceObj, String methodName,
			Object param) throws Exception {
		return Remote.invoke(serviceObj, methodName, param);
	}
}
